//
//  KZCategoryTabelView.m
//  xiaorizi
//
//  Created by kun on 15/10/26.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZCategoryTabelView.h"
#import "KZGlobalApi.h"
#import "categoryModel.h"
#import "KZCategoryCell.h"
#import "KZCategoryEventsTableViewViewController.h"

@interface KZCategoryTabelView ()

@end

@implementation KZCategoryTabelView

- (void)viewDidLoad {
    
    self.url = [KZGlobalApi categoryUrl];
    self.cachePath = [KZGlobalApi categoryCachePath];
    self.refreshType = FLRefreshTypeHeader;
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}





//重写父类方法

-(NSString *)JsonModelPath
{
    return [[NSBundle mainBundle]pathForResource:@"fenlei" ofType:@"json"];
}


- (id)createDataWithNode:(id)node
{
    CategoryModel *model = [CategoryModel initWithDic:node];
    
    return model;
}

-(NSArray *)createDataArray:(NSDictionary *)dic
{
    
    NSArray *arrayData = dic[@"list"];
    
    return arrayData;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // return 500;
    //1 cell 的高度实现
    CGFloat appvieww= ([UIScreen mainScreen].bounds.size.width - 16)/3;
    CGFloat appviewh= appvieww*0.8;
    
    CategoryModel *model = self.data[indexPath.row];
    CGFloat H = (appviewh * model.tags.count/3) + 70;
    return H;
}


//1 界面跳转实现 接口
// [self performSegueWithIdentifier:@"ShowUser" sender:@{@"model":cell.model}];
//2 界面跳转传参接口



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    KZCategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"categoryCell" forIndexPath:indexPath];
    //代理回调
    [cell setCategoryViewBlock:^(UITableViewCell * cell, NSInteger tagUrl,NSString *eventTitle) {
        
        self.hidesBottomBarWhenPushed = YES;
        [self performSegueWithIdentifier:@"categoryEvent" sender:@{@"tagUrl":@(tagUrl),@"title":eventTitle}];
        self.hidesBottomBarWhenPushed = NO;
        
    }];
    
    CategoryModel *model = self.data[indexPath.row];
    cell.model = model;
    // Configure the cell...
    
    return cell;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
   // NSInteger tagID = ((NSNumber *)sender).integerValue;
    
    
    if([segue.identifier isEqualToString:@"categoryEvent"])
    {
        NSDictionary *dataDic = sender;
        KZCategoryEventsTableViewViewController *eventVc = segue.destinationViewController;
        eventVc.eventTitle = dataDic[@"title"];
        eventVc.tagID = ((NSNumber *)dataDic[@"tagUrl"]).integerValue;
      //  eventVc.tagID = tagID;
    }
    
}


@end
